package com.zlk.algorithm.huawei.leetcode.binaryTree;

import com.zlk.algorithm.util.TreeNode;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;


/**
 * @program: algorithm
 * @ClassName Code22_inorderTraversal
 * @description: 二叉树的最大深度
 * @author: slfang
 * @create: 2025-01-08 09:58
 * @Version 1.0
 **/
public class Code23_maxDepth {

    public int maxDepth(TreeNode root) {
        return root==null?0:Math.max(depth(root.left),depth(root.right))+1;
    }

    private int depth(TreeNode node) {
        if(node==null){
            return 0;
        }
        int l = depth(node.left);
        int r = depth(node.right);
        return Math.max(l,r)+1;
    }


}
